<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>用户权限管理</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <c:set var="path" value="${pageContext.request.contextPath}"/>
    <link rel="stylesheet" href="${path}/plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="${path}/plugins/adminLTE/css/AdminLTE.css">
    <link rel="stylesheet" href="${path}/plugins/adminLTE/css/skins/_all-skins.min.css">
    <link rel="stylesheet" href="${path}/css/style.css">
    <script type="text/javascript" src="${path}/plugins/jQuery/jquery-2.2.3.min.js"></script>
    <script type="text/javascript" src="${path}/plugins/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="${path}/plugins/angularjs/toaster.min.css">
    <%-- <script type="text/javascript" src="${path}/plugins/angularjs/angular.min.js"></script>
     <script type="text/javascript" src="${path}/plugins/angularjs/angular-animate.min.js"></script>
     <script type="text/javascript" src="${path}/plugins/angularjs/toaster.min.js"></script>
     <!--引入分页插件资源-->
     <link rel="stylesheet" href="${path}/plugins/angularjs/pagination.css">
     <script type="text/javascript" src="${path}/plugins/angularjs/pagination.js"></script>
     <script type="text/javascript" src="${path}/js/base_pagination.js"></script>
     <script type="text/javascript" src="${path}/js/service/userService.js"></script>
     <script type="text/javascript" src="${path}/js/service/roleService.js"></script>
     <script type="text/javascript" src="${path}/js/controller/baseController.js"></script>
     <script type="text/javascript" src="${path}/js/controller/authorizationController.js"></script>--%>
    <script type="text/javascript">
        function likeQuery() {
            var realname = $("#realnames").val();
            var department = $("#departmentId option:selected");
            if (realname != null && realname != "") {
                if (!(/^[\u4e00-\u9fa5]{1,}$/.test(realname))) {
                    alert("请正确输入姓名");
                    return;
                }
            }
            if ((realname == "" || realname == null) && (department == "" || department == null)) {
                query();
            } else {
                $.ajax({
                    url: "${path}/User/selectByUserLike",
                    type: "post",
                    data: "realName=" + realname + "&departmentId=" + department.val() + "&page=1&pageNum=5",
                    success: function () {
                        location.reload();
                    }
                });
            }
        }

        function selectByUsername(id, name) {
            $("#id").val(id);
            $.ajax({
                url: "${path}/Role/selectByUsername",
                data: "username=" + name,
                dataType: "json",
                success: function (data) {
                    var id;
                    for (let x in data.roles) {
                        id = data.roles[x].id;
                    }
                    $("#check").val(id);
                }
            })
        }

        function query() {
            $.ajax({
                url: "${path}/User/selectAll?page=1&pageNum=5&status=15",
                type: "post",
                success: function () {
                    location.reload();
                }
            });
        }

        function save() {
            var rid = $("#check option:selected").val();
            var id = $("#id").val();
            $.ajax({
                url: "${path}/Role/update",
                data: "uid=" + id + "&rid=" + rid,
                type: "post",
                dataType: "json",
                success: function (status) {
                    if (status == true) {
                        alert("成功");
                        query();
                    } else {
                        alert("失败");
                    }
                }
            })
        }
    </script>
</head>
<body class="hold-transition skin-red sidebar-mini" ng-app="shebao" ng-controller="authorizationController"
      ng-init="findAll()">
<!-- .box-body -->
<toaster-container toaster-options="{'time-out': 1000,'position-class':'toast-center'}"></toaster-container>
<div class="box-header with-border">
    <h3 class="box-title">用户权限管理</h3>
</div>
<div class="box-body">
    <div class="has-feedback">
        <div style="text-align: center;background: #ffff">
            <table align="center" ng-init="searchEntity.state=0">
                <tr>
                    <td style="text-align: right">
                        <span style="white-space: nowrap;display: inline-block">姓名：</span>
                    </td>
                    <%--ng-model="searchEntity.realName"--%>
                    <td><input class="form-control" id="realnames" value="${realName}"></td>
                    <td style="text-align: right">
                        <span style="white-space: nowrap;display: inline-block">部门：</span>
                    </td>
                    <td>
                        <%--ng-model="searchEntity.department"--%>
                        <select class="form-control" id="departmentId">
                            <option value="">全部</option>
                            <%--ng-repeat="d in organlist" value="{{d.id}}" {{d.departmentName}}--%>
                            <c:forEach items="${post}" var="p">
                                <option value="${p.id}">${p.postName}</option>
                            </c:forEach>
                        </select>
                    </td>
                </tr>
            </table>
        </div>
        <div style="text-align: center;padding-top: 10px"><%--ng-click="reloadList()"--%>
            <button class="btn btn-default" onclick="likeQuery()">查询</button>
        </div>
    </div>
</div>
<div class="box-body">
    <!-- 数据表格 -->
    <div class="table-box">

        <!--工具栏-->
        <div class="pull-left">
            <div class="form-group form-inline">
                <div class="btn-group">
                </div>
            </div>
        </div>
        <!--工具栏/-->
        <!--数据列表-->
        <table id="dataList" class="table table-bordered table-striped table-hover dataTable">
            <thead>
            <tr>
                <th class="sorting">用户名</th>
                <th class="sorting">姓名</th>
                <th class="sorting">部门</th>
                <th class="sorting">操作</th>
            </tr>
            </thead>
            <c:forEach var="u" items="${users}">
                <tbody><%--ng-repeat="pojo in list"--%>
                <tr>
                    <td>${u.username}</td>
                    <td>${u.realName}</td>
                    <td>${u.posts.postName}</td>
                    <td class="text-center"><%--ng-click="findRoleWithId(pojo.id)"--%>
                        <button type="button" onclick="selectByUsername(${u.id},'${u.username}')"
                                class="btn bg-olive btn-xs"
                                data-toggle="modal" data-target="#editModal">
                            授权
                        </button>
                    </td>
                </tr>
                </tbody>
            </c:forEach>
        </table>
        <!--数据列表/-->
        <!--分页工具条展示-->
        <%--<tm-pagination conf="paginationConf"></tm-pagination>--%>
        <ul class="pager pull-left">
            <c:if test="${map.nums==null}">
                <li>
                    <c:if test="${map.page>1}">
                        <a href="${path}/User/selectAll?page=${map.page-1}&pageNum=5&status=15">上一页</a>
                    </c:if>

                    <c:if test="${map.page==1}">
                        <a href="#" class="btn btn-default disabled">上一页</a>
                    </c:if>
                </li>
                第 ${map.page} 页&nbsp;&nbsp;&nbsp;共 ${map.num} 页
                <li>
                    <c:if test="${map.page<map.num}">
                        <a href="${path}/User/selectAll?page=${map.page+1}&pageNum=5&status=15">下一页</a>
                    </c:if>

                    <c:if test="${map.page==map.num}">
                        <a href="#" class="btn btn-default disabled">下一页</a>
                    </c:if>
                </li>
            </c:if>
            <li>
                <c:if test="${map.num==null && map.page==null}">
                    <c:if test="${map.pages>1}">
                        <a href="${path}/User/selectByUserLike?page=${map.pages-1}&pageNum=5&realName=${realName}<c:if test="${departmentId!=null}">&department=${departmentId}</c:if>&status=15">上一页</a>
                    </c:if>
                    <c:if test="${map.pages==1}">
                        <a href="#" class="btn btn-default disabled">上一页</a>
                    </c:if>
                    第 ${map.pages} 页&nbsp;&nbsp;&nbsp;共 ${map.nums} 页
                    <c:if test="${map.pages<map.nums}">

                        <a href="${path}/User/selectByUserLike?page=${map.pages+1}&pageNum=5&realName=${realName}<c:if test="${departmentId!=null}">&department=${departmentId}</c:if>&status=15">下一页</a>
                    </c:if>
                    <c:if test="${map.pages==map.nums}">
                        <a href="#" class="btn btn-default disabled">下一页</a>
                    </c:if>
                </c:if>
            </li>
        </ul>
        <br/>

        <div class="text-right">
            <c:if test="${map.counts==null}">
                共 ${map.count} 条数据
            </c:if>
            <c:if test="${map.count==null}">
                共 ${map.counts} 条数据
            </c:if>
        </div>
    </div>
    <!-- 数据表格 /-->
</div>
<!-- 编辑窗口 -->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="width:35%;">
        <div class="modal-content">
            <div class="modal-header"><%--ng-click="emptyuserid()"--%>
                <button id="bt1" type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 id="myModalLabel">用户信息编辑</h4>
            </div>
            <div class="modal-body">
                <table class="table table-bordered table-striped">
                    <tr>
                        <td>角色</td>
                        <td>
                            <input type="hidden" id="id"/>
                            <select class="form-control" ng-model="entity.department" id="check">
                                <c:forEach var="r" items="${role}">
                                    <option value="${r.id}">${r.roleName}</option>
                                </c:forEach>
                            </select>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="modal-footer">
                <%--ng-click="save()"--%>
                <button class="btn btn-success" onclick="save()">保存</button>
                <%--ng-click="emptyuserid()"--%>
                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭
                </button>
            </div>
        </div>
    </div>
</div>
</body>
</html>